#ifndef WIN32DEBUG_H
#define WIN32DEBUG_H

#ifdef _WIN32
#include <Windows.h>
#endif

#include <assert.h>
#include <stdio.h>

extern int G_Verbosity;

namespace Debug
{
inline int ArgDebugPrintF(LPCSTR format, va_list argList)
{
	const unsigned int MAX_CHARS = 1023;
	static char buffer[MAX_CHARS + 1];

	memset(buffer, 0, sizeof(buffer));

	int charsWritten = vsnprintf_s(buffer, _countof(buffer), _TRUNCATE, format, argList);
	buffer[MAX_CHARS] = '\0';
		
	OutputDebugString(buffer);
	OutputDebugString("\n");
	return charsWritten;
}

inline int NDebugPrintF(const char* format, ...)
{
	va_list argList;
	va_start(argList, format);

	int charsWritten = ArgDebugPrintF(format, argList);

	va_end(argList);
	return charsWritten;
}


enum VERBOSE_LEVEL
{
	VERBOSE_LEVEL_HIGH,
	VERBOSE_LEVEL_MID,
	VERBOSE_LEVEL_LOW,
	//COunt
	VERBOSE_LEVEL_COUNT
};

inline void NVerboseDebugPrintF(int verbosity, const char* format, ...)
{
	//Only print when the global verbosity level is high enough
	if(G_Verbosity >= verbosity)
	{
		va_list argList;
		va_start(argList, format);

		ArgDebugPrintF(format, argList);

		va_end(argList);
	}
}

inline void Win32Assert(bool value,const char* info, const char*,  int)
{
	NDebugPrintF(info);
	assert(value);
}
}

#ifdef _DEBUG
/*ASSERT*/
#define NASSERT(value, message) Debug::Win32Assert(value, message, __FILE__, __LINE__);
/*LOGGING*/
#define GET_2ND_ARG(arg1, arg2,...) arg2
#define LOG_FORMAT_CHOOSER(...)								\
		GET_2ND_ARG(__VA_ARGS__, Debug::NDebugPrintF)
#define LOGD(...) LOG_FORMAT_CHOOSER(__VA_ARGS__)(__VA_ARGS__)
#else
#define NASSERT(value, message)
#define LOGD(...)
#endif
#endif